def linear_colormap(colors, max):
 
    rows, cols = np.shape(colors)
   
    position = []  
 
    for i in range(0, rows):    
        position.append(np.int(round((1.0 * i * max)/(rows - 1))))
 
    color_map = []
 
    #遍历所有区间
    for i in range(0, rows - 1):
        #遍历区间中的所有像素点
        for j in range(position[i], position[i + 1]):
            color_r = (colors[i+1][0] - colors[i][0]) * (j- position[i])/(position[i + 1] - position[i]) + colors[i][0]
            color_g = (colors[i+1][1] - colors[i][1]) * (j- position[i])/(position[i + 1] - position[i]) + colors[i][1]
            color_b = (colors[i+1][2] - colors[i][2]) * (j- position[i])/(position[i + 1] - position[i]) + colors[i][2]
            
            color = (color_r, color_g, color_b)
            color_map.append(color)
    #最后一个灰度级没有遍历到，需要进行特殊处理
    color_map.append(colors[rows - 1])
    return color_map
